package com.steakliu.springasync.controller;

import com.steakliu.springasync.service.AsyncService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.task.SimpleAsyncTaskExecutor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

/**
 * 功能说明：
 * <p>
 * Original @Author: steakliu-刘牌, 2022-06-26  11:25
 * <p>
 * Copyright (C)2020-2022  小四的技术之旅 All rights reserved.
 */
@RestController
@AllArgsConstructor
@Slf4j
public class AsyncController {

    final AsyncService asyncService;

    @GetMapping("/async")
    public String async() throws InterruptedException, ExecutionException {
        asyncService.task1();
        String future = asyncService.task2();
        log.info("===task2 result=== {}",future);
        asyncService.task3();
        asyncService.task4();
        return "async";
    }
}
